package com.kcyu.sfherp.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kcyu.sfherp.entity.utilEntity.WeComCheckInData;
import com.kcyu.sfherp.entity.utilEntity.WeComUserDTO;
import com.kcyu.sfherp.service.WeComService;
import com.kcyu.sfherp.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/wecom")
public class WeComController {

    @Autowired
    private WeComService weComService;

    @PostMapping("/getCheckInData/{date}")
    public ResponseResult<List<WeComCheckInData>> getCheckInData(@PathVariable String date) throws IOException, ParseException {
        JSONArray allMember = weComService.getAllMember();
        List<String> userid = allMember.stream().map(o -> (String) ((JSONObject) o).get("userid")).collect(Collectors.toList());
        return new ResponseResult<>(200, weComService.getCheckInData(date, userid));
    }

    @PostMapping("getAllMemberDict")
    public ResponseResult<List<WeComUserDTO>> getAllMemberDict() throws IOException {
        return new ResponseResult<>(200, weComService.getAllMemberDict());
    }
}
